<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>网络服务平台</title>
    <link rel="stylesheet" type="text/css" href="../../../../js/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../../../js/easyui/themes/icon.css">
    <script type="text/javascript" src="../../../../js/easyui/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="../../../../js/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../../../js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#inLineWordGrid').datagrid({
                title:'新闻内联列表',
                iconCls:'icon-save',
                width:"100%",
                height:460,
                nowrap:false,
                striped:true,
                collapsible:true,
                url:'/management/news/fetchInLineWords.action',
                queryParams:{"inIndex":"-1", "indexLevel":"-1"},
                remoteSort:false,
                idField:'id',
                frozenColumns:[
                    [
                        {field:'ck', checkbox:true},
                        {"width":350, "field":"word", "title":"标题"},
                        {"width":350, "field":"url", "title":"URL"}
                    ]
                ],
                columns:[
                    [
                        {"width":130, "field":"createDate", "title":"发布日期"},
                        {"width":80, "field":"id", "title":"操作",
                            formatter:function (value, rowData, rowIndex) {
                                <s:if test="1 == #session._user_role_">
                                return '<a onclick="deleteInLineWord(\'' + value + '\');" href="#">删除</a>';
                                </s:if>
                                <s:else>
                                return '';
                                </s:else>
                            }
                        }
                    ]
                ],
                pagination:true,
                rownumbers:true,
                toolbar:[
                    {"iconCls":"icon-add", "handler":function () {
                        openCreateInLineWord();
                    }, "text":"添加内联", "title":"添加内联", "id":"btnAdd"}
                    ,
                    {
                        text:'编辑内联',
                        iconCls:'icon-save',
                        handler:function () {
                            editInLineWord();
                        }
                    }
                ]
            });

            var p = $('#inLineWordGrid').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    onBeforeRefresh:function () {
                    }
                });
            }
        });

        function openCreateInLineWord() {
            $('#inLineWordForm').form('clear');
            $('#itemEditorDialog').show();
            $('#itemEditorDialog').dialog({
                width:240,
                title:'添加内联',
                modal:true
            });
        }

        function createInLineWord() {
            $("#inLineWordForm").form('submit', {
                url:"/management/news/inLineWordForm.action",
                onSubmit:function () {
                    return $(this).form('validate');
                },
                success:function (data) {
                    //   alert(data);
                    data = eval('(' + data + ')');

                    if (!data.successful) {
                        $.messager.show({
                            title:'提示信息',
                            msg:'保存失败！原因： ' + data.errorMessage
                        });

                        return;
                    }

                    $.messager.show({
                        title:'提示信息',
                        msg:'保存成功！'
                    });

                    $('#inLineWordGrid').datagrid('reload');
                    closeForm();
                }
            });
        }

        function editInLineWord() {
            var rows = $('#inLineWordGrid').datagrid('getSelections');
            var row = $('#inLineWordGrid').datagrid('getSelected');
            if (rows.length == 1) {
                $('#inLineWordForm').form('load', {
                    'inLineWordForm.id':row.id,
                    'inLineWordForm.word':row.word,
                    'inLineWordForm.url':row.url,
                    'inLineWordForm.createDate':row.createDate
                });

                $('#itemEditorDialog').show();
                $('#itemEditorDialog').dialog({
                    title:'编辑内联',
                    modal:true
                });
            } else if (rows.length < 1) {
                $.messager.alert('警告', '请选择一条记录!', 'warning');
            }
            else {
                $.messager.alert('警告', '一次只能修改一条记录!', 'warning');
            }
        }

        function deleteInLineWord(id) {
            $.messager.confirm('删除内联', '你确定要删除内联吗？', function (data) {
                if (!data) {
                    return;
                }

                $.getJSON("/management/news/deleteInLineWord.action?id=" + id, function (data1) {
                    if (data1.successful) {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除内联成功！'
                        });

                        var index= $("#inLineWordGrid").datagrid('getRowIndex',id);
                        $('#inLineWordGrid').datagrid('deleteRow',index);
                    } else {
                        $.messager.show({
                            title:'提示信息',
                            msg:'删除内联失败！'
                        });
                    }
                });
            });
        }

        function closeForm() {
            $('#itemEditorDialog').dialog('close');
        }

        function query() {
            var wordName = $("#wordName").val();
            var queryParams = $('#inLineWordGrid').datagrid('options').queryParams;

            queryParams.wordName = wordName;

            $('#inLineWordGrid').datagrid('options').queryParams = queryParams;
            $("#inLineWordGrid").datagrid('reload');
        }

    </script>

</head>

<body class="easyui-layout">
<s:if test="null == #session._login_user_">
    <script type="text/javascript">
        top.location.href = '/admin';
    </script>
</s:if>
<div region="center" style="height:600px;padding:10px;background:#efefef;">
    <div id="p" class="easyui-panel" title="搜索" icon="icon-search" style="height:80px;padding:10px;">
        <table style="border: #15428B; border-style: solid; border-width: 1px ">
            <tr>
                <td><label>标题:</label></td>
                <td>&nbsp;<input name="wordName" id="wordName"/></td>
                <td style="width:20px"></td>
                <td><a class="easyui-linkbutton" onclick="query()">搜索</a></td>
            </tr>
        </table>
    </div>
    <div id="p1" class="easyui-panel" style="height:500px;">`
        <table id="inLineWordGrid"></table>
    </div>
</div>

<div id="itemEditorDialog" icon="icon-save" title="内联管理" style="height:400;width:400;display:none;padding:5px;">
    <form method="post" id="inLineWordForm" name="inLineWordForm">
        <table>
            <tr>
                <td><label>标题：</label></td>
                <td><input class="easyui-validatebox" id="word" name="inLineWordForm.word" required="true"/></td>
            </tr>
            <tr>
                <td><label>url：</label></td>
                <td><input class="easyui-validatebox" id="url" name="inLineWordForm.url"/></td>
            </tr>
        </table>
        <div class="toolbar" style="padding:10px;">
            <a href="#" onclick="closeForm()" class="easyui-linkbutton" iconCls="icon-cancel"
               style="float: right;">取消</a>
            <a href="#" onclick="createInLineWord()" class="easyui-linkbutton" iconCls="icon-ok" style="float: right;">确定</a>
        </div>
        <input type="hidden" name="inLineWordForm.id"/>
        <input type="hidden" name="inLineWordForm.createDate"/>
    </form>
</div>

</body>
</html>